﻿using System; 
using System.Data;
using System.Collections.Generic; 
using JOIN.Rights.Model;
using Kevin.Framework.Data;

/*------------------------------------------------------------------------
   苏州捷安信息科技有限公司 版权所有			
   文件名: TU_User.cs
   作 者 : 席吉波
   日 期 : 2012/10/12 16:10:54
   备 注 : 当您对本文件更改时请写明修改人、修改日期以及是由
  ------------------------------------------------------------------------
*/

namespace JOIN.Rights.BLL
{
	 	//TU_User
    public partial class UserBLL1 : BLLBase<UserInfo>,ISelect<UserInfo>
	{
		//private readonly ITU_User dal=DataAccess.CreateTU_User();
		public UserBLL1(UserInfo entity)
			:base(entity)
		{
		
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="operationMode">操作模式</param>
        /// <param name="jsonEntity">前台javascript传过来的JSON实体</param>
        public UserBLL1(string operationMode, string jsonEntity)
        {
            OperState cmd = (OperState)Enum.Parse(typeof(OperState), operationMode);
            UserInfo entity = ConvertJSON2Entity(jsonEntity);
            base.OperState = cmd;
            base.Entity = entity;
            base.ServiceResult = new ServiceResult<UserInfo>();
            base.ServiceResult.Successed = true;
            base.ServiceResult.Object = base.Entity;
        }

        #region 查询方法

        protected override bool PreSaveProcess()
        {
            if (base.OperState == BLL.OperState.Add)
            {
                UserInfo exsitUser = new UserInfo();
                exsitUser.UserNO = Entity.UserNO;
                if (exsitUser.SelectedByProperties().Rows.Count > 0)
                {
                    base.ServiceResult = new ServiceResult<UserInfo>();
                    base.ServiceResult.Object = Entity;
                    base.ServiceResult.Successed = false;
                    base.ServiceResult.ErrorMsg = "用户:" + Entity.UserNO + " 已经存在！";
                    return false;
                }
                
            }
            return true;            
        }
        /// <summary>
        /// 获取集合
        /// </summary>
        /// <param name="pageSize">分页记录数</param>
        /// <param name="pageIndex">页码索引</param>
        /// <returns></returns>
        public ServiceResult<UserInfo> SelectByProperties(int pageSize, int pageIndex)
        {
            this.ServiceResult = new ServiceResult<UserInfo>();
            try
            {
                int recordCount =0;
                List<UserInfo> list = base.Entity.SelectedByProperties<UserInfo>(out recordCount,pageSize,pageIndex);
                
                ServiceResult.Successed = true;
                ServiceResult.RecordCount = recordCount;
                ServiceResult.List = list;
                
            }
            catch(Exception ex){
                ServiceResult.ErrorMsg = "数据查询失败:"+ex.Message;
                ServiceResult.Successed = false;
                ServiceResult.RecordCount = 0;
                ServiceResult.List = null;
            }

            return ServiceResult;
        }

        #endregion

        
    }
}